
<%@ page import="java.util.LinkedHashMap,
				 java.util.Iterator,
				 java.util.ArrayList,
				 com.scalar.chiptrack.adaptor.Adaptor,
                 com.scalar.chiptrack.utils.ConfigManager,
                 com.scalar.chiptrack.adaptor.AdaptorList" %>

<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/struts-nested.tld" prefix="nested" %>
<%@ taglib uri="/WEB-INF/chiptrack-tags.tld" prefix="chiptrack" %>

<%String chipTracContext = "/" + ConfigManager.getChipTracContext(); try {%>

<HTML><HEAD><TITLE>Scalarsoft - ChipTrac</TITLE>
<META http-equiv=Content-Type content="text/html; charset=windows-1252">
<LINK href="<%=chipTracContext%>/jsp/includes/stylesheets/scalarsoft.css" type="text/css" rel="stylesheet">
<script src="<%=chipTracContext%>/jsp/includes/scripts/functions.js"></script>
<script src="<%=chipTracContext%>/jsp/includes/scripts/validations.js"></script>

<script language="javascript">

var text = "";
var errtext = "";
var pa = "";

function debugInfo(message)
{
    if( message.indexOf("<") > -1 )
    {
        errtext +=message+"\n";
        pa=document.getElementById("errors");
        pa.innerHTML = errtext;
    }

    text +=message+"\n";
	//document.all["debug"].innerHTML = text;
	document.run_adaptor_form.debugarea.value = text;
}


function submit()
{
    var adaptorNameString = "";
    errtext = "";
    pa.innerHTML = "";

    if( typeof document.run_adaptor_form.adaptorNames != "undefined" )
    {
        debugInfo("Initializing server");
        if(typeof document.run_adaptor_form.adaptorNames.length == 'undefined')
        {
            document.run_adaptor_form.adaptorNames.disabled = true;
            if( document.run_adaptor_form.adaptorNames.checked )
            {
                var adaptorName = document.run_adaptor_form.adaptorNames.value;
                adaptorNameString = adaptorNameString +adaptorName +",";
            }
        }
        else
        {
            for( var i=0; i<document.run_adaptor_form.adaptorNames.length; i++ )
            {
                document.run_adaptor_form.adaptorNames[i].disabled = true;
            }

            for( var i=0; i<document.run_adaptor_form.adaptorNames.length; i++ )
            {
                if( document.run_adaptor_form.adaptorNames[i].checked )
                {
                    var adaptorName = document.run_adaptor_form.adaptorNames[i].value;
                    adaptorNameString = adaptorNameString +adaptorName +",";
                }
            }
         }

        if( adaptorNameString.length > 0 )
        {
            if( document.proxy.startCommunicator() == "success" )
             {
                debugInfo("Sending Request to server......");
             }

            //debugInfo( "Processing Request......."+adaptorName );
            document.proxy.startRequest( adaptorNameString );

            while( document.proxy.waitForResponse() != false )
            {
                debugInfo( document.proxy.receiveResponse() );
            }

            if( document.proxy.endRequest() == "end" )
            {
                debugInfo( "request end" );
            }
        }

        if( typeof document.run_adaptor_form.adaptorNames.length == 'undefined')
        {
            document.run_adaptor_form.adaptorNames.disabled = false;
        }
        else
        {
            for( var i=0; i<document.run_adaptor_form.adaptorNames.length; i++ )
            {
                document.run_adaptor_form.adaptorNames[i].disabled = false;
            }
        }
    }
 }


</script>

<META content="MSHTML 5.50.4807.2300" name=GENERATOR></HEAD>
<BODY bgColor="#ffffff" leftMargin="0" topMargin="0" marginheight="0" marginwidth="0">

<!-- Top Header Start-->

<%@ include file="/jsp/includes/header.jsp" %>

<!-- Top Header End-->

<TABLE cellSpacing=0 cellPadding=0 width="100%" border="0">
        <TR>
        <TD colspan="3"><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=30></TD>
        </TR>
 <TR>
	<td width='180' valign='top' background='<%=chipTracContext%>/jsp/includes/images/left_red_bg.gif'>
     <!-- Side Navigation start -->
    <%@ include file="/jsp/operations/reports_side_menu.jsp" %>
     </TD>
    <!-- end of the side navigations -->

    <TD bgcolor="#ffffff">
        <IMG height=9 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=8>
    </TD>
    <TD bgcolor="#ffffff">
        <IMG height=480 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=8>
    </TD>
        <form name="run_adaptor_form"  action="<%=chipTracContext%>/runAdaptor.do">
        <TD valign="top" width="100%" >
            <table border="0" width="100%" align=center>

            <tr><td colspan="5" class="NArialW" align="center">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;On Demand Adaptor</td></tr>
            <tr><td colspan="5" class="NArialW" align="center">&nbsp;&nbsp;</td></tr>
            <tr><td colspan="5" class="NArialL" align="left"><FONT id="errors" styleClass="NArialL" color='FF0000'></FONT></td></tr>
            <tr><td width="100%">
            <table border = "0" width="100%" align=center>
             <tr><td >&nbsp;</td></tr>
             <tr><td >&nbsp;</td></tr>
            <tr> <td width="40%">
            <%
    	    String servletUrlPath = request.getScheme() + "://"+ request.getServerName()+":"+ request.getServerPort()+request.getContextPath();
    	    LinkedHashMap map = (LinkedHashMap)request.getAttribute("adaptorList");
		    Iterator it = map.keySet().iterator();
		    while(it.hasNext())
            {
			    String key = (String)it.next();
                if ( key.indexOf(" - ") != -1 )
                {
            %>
		     &nbsp;&nbsp;&nbsp;&nbsp;<input type="checkbox" name="adaptorNames" value="<%= key%>"><font class="NArialL" ><%= key%></font><br>
	        <%
                }
			    /*Adaptor adaptor = (Adaptor)map.get(key);
			    ArrayList list = adaptor.getAdaptorList();*/
		    }
            %>
        </td></tr>
         <tr><td width="40%">&nbsp;</td></tr>
        
         <tr><td align=center>
    	<IMG height=10 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=1><br>
             <a href="javascript:submit()"><img border="0" src="<%=chipTracContext%>/jsp/includes/images/submit.gif" width="53" height="17" onmouseover="window.status='Click to Run Adaptors';return true" onmouseout="window.status='';return true" title="Click here to Run Adaptors"></a></td></tr>       
        </table></td>
        <td width="60%" valign=top><div id=debug><textarea name=debugarea rows=20 cols=75 class="txfield" readonly=true autoscroll></textarea></div></td>

        </tr>

        <tr><td colspan=3>
	    <OBJECT name=proxy classid="clsid:CAFEEFAC-0016-0000-FFFF-ABCDEFFEDCBA"
          height="0"
          width="0"
          codebase="http://java.sun.com/update/1.6.0/jinstall-6-windows-i586.cab">
     <PARAM NAME="code" VALUE="com.scalar.chiptrack.workflow.RunAdaptorApplet.class">
     <PARAM NAME="codebase" VALUE="<%=chipTracContext%>">
     <PARAM NAME="name" VALUE="proxy">
     <PARAM name="type" value="application/x-java-applet;version=1.6">
	 <PARAM NAME="archive" VALUE="workflow.jar" > >
	 <param name="contextURL" value="<%=servletUrlPath%>" >
    </OBJECT>
	<!-- <applet name=proxy
			code="com.scalar.chiptrack.workflow.RunAdpatorApplet.class"
			archive="workflow.jar"
			codebase="<%=chipTracContext%>"
			width=0 height=0 VIEWASTEXT>
	</applet> --></td></tr>
      <TR>
        <TD colspan="4"><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=20></TD>
    </TR>          
     </table>

     <table border="0" width= "100%">
     <%
	        ArrayList adaptorList = (ArrayList) request.getAttribute ("runInfoSelectList");
	        if (adaptorList == null) adaptorList = new ArrayList();
	        if(adaptorList.size()==0)
            {
        %>
         <font class="NArialL"><font color="FF0000"><li>Adaptors Last Running Information: Not found </font></font>
     <%
	        }
            else
            {
        %>
    <tr bgcolor="#993333">
            <td width="20%" align="center" class="NArialL" ><font color="#FFFFFF" >Adaptor Name</font></td>
            <td width="20%" align="center" class="NArialL"><font color="#FFFFFF" >Last Updated Time</font></td>
            <td width="40%" align="center" class="NArialL" ><font color="#FFFFFF" >File Name</font></td>
            <td width="20%" align="center" class="NArialL" ><font color="#FFFFFF" >Latest Report Upload Time</font></td>
    </tr>
        <logic:iterate id="adaptorrunInfo" name="runInfoSelectList" indexId="iterateIdx">
    <% if( Integer.parseInt( iterateIdx.toString() ) % 2 == 0 ) { %>
    <tr bgcolor='#FFFFEE'>
    <%} else { %>
    <tr bgcolor='#DEE1E2'>
    <% } %>
       <td  width="20%" align="center"><font class="NArialL"> <bean:write name="adaptorrunInfo" property ="adaptorName"/></font></td>
       <td  width="20%" align="center"><font class="NArialL"> <bean:write name="adaptorrunInfo" property ="adaptorRunTime"/></font></td>
       <td  width="40%"  align="center"><font class="NArialL"> <bean:write name="adaptorrunInfo" property ="fileName" filter="false"/></font></td>
       <td  width="20%" align="center"><font class="NArialL"> <bean:write name="adaptorrunInfo" property ="uploadDate" filter="false"/></font></td>
       </tr>
       </logic:iterate>

    <% } %>
</table>
<input type="hidden" name="action">
</form>
 <!-- till here body-->
<BR><BR><BR>
<TD bgcolor="#ffffff"><IMG height=1 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=1></TD>
</tr>
<!-- Footer starts here -->
<%@ include file="/jsp/includes/footer.jsp" %>
<!-- footer end here -->
</table>
</BODY>
</HTML>
<% }
catch(Exception e )
{
    e.printStackTrace();
}%>